package com.example.microinvestweb.controller.user;
import com.example.microinvestcommon.pojo.Result;
import com.example.microinvestcommon.util.ThreadLocalUtil;
import com.example.microinvestcommon.vo.*;
import com.example.service.OtherBusinessService;
import com.example.microinvestuser.service.user.UserGetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/userStock")
public class UserGetController {

    private final OtherBusinessService businessService;

    private final UserGetService userGetService;

    @Autowired
    public UserGetController(OtherBusinessService businessService,UserGetService userGetService){
        this.businessService=businessService;
        this.userGetService=userGetService;
    }
    //用户个人信息
    @GetMapping("/getUserInfo")
    public Result<UsersVo> getUserInfo(){
        Result result=userGetService.getUserInfo();
        return result;
    }

    //用户收藏股票
    @PostMapping("/starStock")
    public Result<String> userStarStock(@RequestParam String stockSymbol){
        Map<String,Long> map = ThreadLocalUtil.get();
        Long userId=map.get("userId");
        Result result=businessService.userStarStock(userId,stockSymbol);
        return result;
    }

    //用户查看收藏股票信息
    @GetMapping("/getStarStock")
    public Result<List<UserStockFavoritesVo>> getUserStarStock(){
        Result result=userGetService.getUserStockFavorites();
        return result;
    }

    //取消收藏
    @PostMapping("/cancelStarStock")
    public Result cancelStarThisStock(@RequestParam String stockSymbol){
        Result result=businessService.userCancelStarThisStock(stockSymbol);
        return result;
    }

    //用户获取是否收藏过次股票信息
    @GetMapping("/isStarThisStock")
    public Result isStarThisStock(String stockSymbol){
        Map<String,Long> map = ThreadLocalUtil.get();
        Long userId=map.get("userId");
        Result result=userGetService.isStarThisStock(userId,stockSymbol);
        return result;
    }

    //用户查看自己购买股票信息
    @GetMapping("/getBuyStock")
    public Result<List<BuyStockVo>> getUserBuyStock(){
        Result result=userGetService.getUserBuyStock();
        return result;
    }

    //用户查看自己卖出股票信息
    @GetMapping("/getSellStock")
    public Result<List<SellStockVo>> getUserSellStock(){
        Result result=userGetService.getUserSellStock();
        return result;
    }

    //返回总订单信息
    @GetMapping("/getUserOrder")
    public Result<List<UserOrderVo>> getUserOrder(){
        Result result=userGetService.getUserOrder();
        return result;
    }

    //根据股票名称返回Order
    @GetMapping("/getUserOrderBySymbol")
    public Result<List<UserOrderVo>> getUserOrderBySymbol(String stockSymbol){
        Result result=userGetService.getUserOrderByStockSymbol(stockSymbol);
        return result;
    }

    /**
     *
     * @param searchString
     * @return 根据SearchString进行搜索
     */
    @GetMapping("/searchSymbol")
    public Result<List<StockNumSymbolVo>> userSearchSymbol(String searchString){
        Result result=userGetService.userSearchSymbol(searchString);
        return result;
    }

    /**
     *
     * @return 返回目前持有的股票数量以及花费过的钱
     */
    @GetMapping("/getUserStockSummary")
    public Result<List<UserStockSummaryVo>> getUserStockSummary(){
        Result result=userGetService.getUserStockSummary();
        return result;
    }


}
